import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import vue from "@vitejs/plugin-vue";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
      "#": fileURLToPath(new URL("./types", import.meta.url)),
      'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
    },
  },
  server: {
    proxy: {
      "/m.api": {
        // 匹配请求路径，localhost:3000/snow
        target: "http://192.168.1.188:8080", // 代理的目标地址
        changeOrigin: true, // 开发模式，默认的origin是真实的 origin:localhost:3000 代理服务会把origin修改为目标地址
        ws: true, // 是否代理websockets
        rewrite: (path) => path.replace(/^\/api/, ""), // 路径重写，本项目不需要重写
      },
      "/upload/admin":{
        target:"http://192.168.1.188:8080",
        changeOrigin:true
      }
    },
  },
});
